home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / maximus / mul100.zip / MAXPLAY.SCR < prev    next >
Text File  |  1993-02-01  |  7KB  |  212 lines

  1.  
  2. // MAXPLAY.SCR  --  Play Maximus-CBCS Tunes  --  Version 1.00
  3. //
  4. // Script program for MUL - the Maximus User Language
  5. // MUL is (C) Copyright 1990-93 by CodeLand Australia
  6. //
  7. // USAGE:       MUL -pMaxplay                   or
  8. //              MUL -pMaxplay Tunes.Bbs         or
  9. //              MUL -pMaxplay /Yell1            or
  10. //              MUL -pMaxplay Tunes.Bbs /Yell1
  11.  
  12. char *banner = "MAXPLAY v1.00";             // Script banner
  13. char *desc = "Play Maximus-CBCS TUNES";     // Description
  14. char *abort = "\nKeyboard ABORT\n";         // Keyboard abort
  15. char fname[80];                             // Tunes file name
  16. long fp;                                    // Tunes file handle
  17. char tune[40];                              // Tune to play
  18.  
  19. int note;                                   // Note to play
  20. int duration;                               // Duration for play
  21.  
  22. int gotnote;                                // Got note flag
  23. int notedisplay;                            // Display control flag
  24. int selfound=0;                             // Selection found flag
  25. int rotor;                                  // Rotor display flag
  26.  
  27. main (int argc, char *arg1, char *arg2)     // Main program
  28. {
  29.     char bf[256];                           // File read buffer
  30.  
  31.     printf ("\n%s - %s\n",banner,desc);     // Announce
  32.     getcmdline (argc,arg1,arg2);            // Get the command line
  33.  
  34.     openfile (fname);                       // Open the tunes file
  35.  
  36.     // Display selection
  37.     if (*tune) printf ("\nSearching \"%s\" for \"%s\" .. ",fname,tune);
  38.     else printf ("\nPlaying file \"%s\"\n",fname);
  39.  
  40.     while (1) {                             // Main loop
  41.         if (!fgets (bf,256,fp)) break;      // Abort if end of file
  42.  
  43.           if (strchr (bf,'*')) {            // Tune start
  44.             if (*tune) {                    // If tune selected
  45.                  if (thetune (bf)) {        // If this is the tune
  46.                      ++selfound;            // Flag tune as found
  47.                      puts(" \n");           // Cleanup after search
  48.                      playtune (bf);         // Play the tune
  49.                      keyabort ();           // Abort if key hit
  50.                      break;                 // And exit
  51.                 }
  52.                 showrotor ();               // Display search rotor
  53.             }
  54.             else {
  55.                 playtune (bf);              // Else play the tune
  56.                 Play (0,1000);              // Pause one second between tunes
  57.             }
  58.  
  59.             if (keyabort ()) break;         // Abort if key hit
  60.             if (feof (fp)) break;           // Abort if end of file
  61.         }
  62.     }
  63.  
  64.     fclose (fp);                            // Close the tunes file
  65.  
  66.     // If selection not found report it
  67.     if (*tune && !selfound) {               
  68.         printf ("\nTune \"%s\" NOT found\n",tune);
  69.     }
  70.  
  71.     saybibi ();                             // Was it good for you too?
  72. }
  73.  
  74. // openfile - opens a text file for reading
  75. openfile (char *nam)
  76. {
  77.     fp=fopen (nam,"r");
  78.     if (!fp) {
  79.         printf ("\nERROR opening file \"%s\"\n",nam);
  80.         saybibi ();
  81.         exit ();
  82.     }
  83. }
  84.  
  85. // Check for selected tune match
  86. thetune (char *line)
  87. {
  88.     char *p;
  89.  
  90.     p=strchr (line,'*');
  91.     p++;
  92.     while (isspace (*p)) p++;
  93.     if(!strnicmp(p,tune,strlen(tune))) return 1;
  94.  
  95.     return 0;
  96. }
  97.  
  98. // Check for keyboard abort
  99. keyabort ()
  100. {
  101.     if (kbhit ()) {                         // Abort if key hit
  102.         getch ();                           // Get the character
  103.         putch (' ');                        // Rotor cleanup
  104.         puts (abort);                       // Acknowledge abort
  105.         ++selfound;                         // Turn off not found message
  106.         return 1;                           // Exit play loop
  107.     }
  108.  
  109.     return 0;
  110. }
  111.  
  112. // Convert a string to upper case
  113. stringtoupper (char *s)
  114. {
  115.     while (*s) { *s=toupper(*s); s++; }
  116. }
  117.  
  118. // Display the rotor 8-)
  119. showrotor ()
  120. {
  121.      if (++rotor>16) rotor=1;
  122.      
  123.      if (rotor==4)       puts ("-\b");
  124.      else if (rotor==8)  puts ("\\\b");
  125.      else if (rotor==12) puts ("|\b");
  126.      else if (rotor==16) puts ("/\b");
  127. }
  128.  
  129. // Play the tune
  130. playtune (char *bf)
  131. {
  132.     printf ("\n");                          // Display blank line
  133.  
  134.     do {                                    // Skip dupe comment lines
  135.         printf ("%s",bf);                   // Display comment line
  136.         if (!fgets (bf,256,fp)) return;     // Abort if end of file
  137.     } while (strchr (bf,'*'));              // While a comment line
  138.  
  139.     gotnote=0;                              // Reset flag for tune start
  140.     notedisplay=5;                          // Reset display control
  141.  
  142.     do {                                    // Play the tune
  143.         if (strlen (bf)<2) break;           // Check for end of tune
  144.  
  145.         playline (bf);                      // Play the line
  146.         if (kbhit ()) break;                // Abort if key hit
  147.  
  148.     } while (fgets (bf,256,fp));            // While lines available
  149.  
  150.     if (notedisplay!=5) printf ("\n");      // End the note display line
  151. }
  152.  
  153. // Play notes in line buffer
  154. playline (char *p)
  155. {
  156.     char *ptr=strtok (p," \t\n\r");         // Get first token
  157.  
  158.     if (!*ptr) return;                      // Abort if none
  159.  
  160.     do {                                    // Process the line
  161.         if (kbhit ()) break;                // Abort if key hit
  162.  
  163.         if (!gotnote) {                     // If waiting for note value
  164.             note=atoi (ptr);                // Get note value
  165.             gotnote++;                      // Increment flag
  166.         }
  167.         else {                              // Else get duration value
  168.             duration=atoi (ptr);            // Get duration value
  169.             gotnote=0;                      // Reset got note flag
  170.  
  171.             printf ("N:%4d D:%4d  ",        // Display the note & duration
  172.                 note,duration);
  173.  
  174.             if (!--notedisplay) {           // Decrement display control
  175.                 notedisplay=5;              // Reset the display control flag
  176.                 printf ("\n");              // Terminate the line
  177.             }
  178.  
  179.             Play (note,duration);           // Play the note
  180.         }
  181.     } while (ptr=strtok (0," \t\n\r"));
  182. }
  183.  
  184. // Get the command line
  185. getcmdline (int argc, char *arg1, char *arg2)
  186. {
  187.     // Load command line tunes file and tune selection options
  188.  
  189.     strcpy (fname,"TUNES.BBS");             // Default tunes name
  190.  
  191.     if (argc) {
  192.         if (arg1[0] == '/') strcpy (tune,arg1+1);
  193.         else strcpy (fname,arg1);
  194.     }
  195.     if (argc>1) {
  196.         if (arg2[0] == '/') strcpy (tune,arg2+1);
  197.         else strcpy (fname,arg2);
  198.     }
  199.  
  200.     stringtoupper (tune);                   // Change string to upper case
  201.     stringtoupper (fname);                  // Change string to upper case
  202. }
  203.  
  204. // Byebye
  205. saybibi ()
  206. {                             
  207.     puts ("\nMaxPlay done!\n");
  208. }
  209.  
  210. // End of script
  211.  
  212.